// components/tabBar/tabBar.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        'activeIndex': {
            type: String,
            observer: function () {
                let self = this;
                let tabBar_1 = "tabbarData[0].iconPath";
                let tabBar_2 = "tabbarData[1].iconPath";
                let tabBar_3 = "tabbarData[2].iconPath";
                if (self.data.activeIndex == 0){ //选中首页
                    self.setData({
                        [tabBar_1]: '../../images/index_h.png',
                        [tabBar_2]: '../../images/shopping.png',
                        [tabBar_3]: '../../images/my.png',
                        activeIndex: self.data.activeIndex,
                    })
                } else if (self.data.activeIndex == 1) { //选中购物车
                    self.setData({
                        [tabBar_1]: '../../images/index.png',
                        [tabBar_2]: '../../images/shopping_h.png',
                        [tabBar_3]: '../../images/my.png',
                        activeIndex: self.data.activeIndex,
                    })
                } else if (self.data.activeIndex == 2) { //选中我的
                    self.setData({
                        [tabBar_1]: '../../images/index.png',
                        [tabBar_2]: '../../images/shopping.png',
                        [tabBar_3]: '../../images/my_h.png',
                        activeIndex: self.data.activeIndex,
                    })

                }
            }
        },
    },

    /**
     * 组件的初始数据
     */
    data: {
        tabbarData:[{
            text:'首页',
            iconPath:'../../images/index_h.png'
        }, {
            text: '购物车',
            iconPath: '../../images/shopping.png'
        }, {
            text: '我的',
            iconPath: '../../images/my.png'
        },],
        activeIndex:0,
    },

    /**
     * 组件的方法列表
     */
    methods: {
        clickTabbar:function(e){
            let self = this;
            switch(e.currentTarget.dataset.text){
                case "首页":
                    wx.reLaunch({
                        url: '/pages/index/index'
                    })
                    break;
                case "购物车":
                    wx.navigateTo({
                        url: '/pages/shoppingCart/shoppingCart'
                    })
                    break;
                case "我的":
                    wx.navigateTo({
                        url: '/pages/my/my'
                    })
                    break;
            }
        }
    }
})
